/**
 * 
 */
var _game;
function shipDeployer ()
{
	var shipLoc = $.parseJSON(_game.myShipPlacement);
	$.each(shipLoc,function(key,val)
			{
				if (val[0][0]==val[val.length-1][0])
				//Ship hasn't been turned
				{
					placeShipToCell("#"+key,"#L"+String(val[0][0])+"\\,"+val[0][1],false,false);
				}
				else
				//Ship has been turned
				{
					turnShipHelper($("#"+key),false);
					placeShipToCell("#"+key,"#L"+String(val[0][0])+"\\,"+val[0][1],true,false);
				}
			});
	replayArrayHandler();
	
}

function replayArrayHandler()
{
	var replayArray = _game.replayArray;
	function replayArrayHandlerHelper(index)
	{
		if (replayArray[index][0]==0)
		{
			playerMoveHandler(replayArray[index]);
		}
		else
		{
			opponentMoveHandler(replayArray[index]);
		}
		if ((index+1)<replayArray.length)
		{
			if (_paused)
			{
				setTimeout(replayArrayHandlerHelper,1000,index);
			}
			else
			{
			setTimeout(replayArrayHandlerHelper,1000,index+1);
			}
		}
	
	}
	setTimeout(replayArrayHandlerHelper,1000,0);
	
}
function playerMoveHandler(moveInfoArray)
//My move info as an Array: [player,cell,hit/miss,drowned ships loc]
{
	if (moveInfoArray[2]=="false")
	{
		$(moveInfoArray[1]).css("background-color","blue");
	}
	else if (moveInfoArray[3]!=null)
	{
		paintOpponent(moveInfoArray[3],"red");
	}
	else
	{
		$(moveInfoArray[1]).css("background-color","orange");
	}
}
function opponentMoveHandler(moveInfoArray)
{
	paintSingleCell(moveInfoArray[1],"red");
}

function initReplay (gameNr)
{
	_game = $.parseJSON(localStorage.getItem(String(gameNr)));
}

